<template>
	<view id="mine-details-two">
		<view class="head">
			<image class="diamonds_img" src="@/static/sy/mine-detailsmine-details/diamonds.png" mode=""></image>
			<view class="head_box">
				<image class="head_box_l" :src="info.activityImg" mode="aspectFill"></image>
				<view class="head_box_r">
					<view class="head_box_r_t ellipseHide">{{info.name}}</view>
					<view class="head_box_r_b">{{typeName}}</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="title">商品类型</view>
			<scroll-view scroll-x="true" class="scroll_view">
				<view class="type">
					<view class="type_box" :class="typeIndex==index?'type_box_change':''"
						v-for="(item,index) in info.commodityListDTO" :key="index" @click="changeType(item,index)">
						{{item.commodityType}}
					</view>
				</view>
			</scroll-view>
			<view class="title">商品面值</view>
			<view class="face_value">
				<view class="face_value_box" :class="faceValueIndex==fIndex?'face_value_box_change':''"
					v-for="(item,fIndex) in partyCommodityListDTO" :key="fIndex" @click="changeFace(item,fIndex)">
					<image class="check_true_img" src="@/static/sy/mine-detailsmine-details/check_true.png"
						v-if="faceValueIndex==fIndex" mode=""></image>
					<view class="face_value_sell_out" v-if="item.salesStatus!=1">售罄</view>
					<view class="face_value_box_name ellipseHide" :class="item.salesStatus!=1?'sell_out_active':''">{{item.couponName}}</view>
					<view class="face_value_box_price" :class="item.salesStatus!=1?'sell_out_active':''">
						<text>￥</text>
						<text style="font-size: 40rpx;font-weight: bold;">{{item.sellPrice}}</text>
					</view>
					<view class="old_price" :class="item.salesStatus!=1?'sell_out_active':''">官方价:¥{{item.originalPrice}}</view>
				</view>
			</view>
			<view class="expected_reward" v-if="awardType!=3">
				预计获得{{awardAmount}}<text v-if="awardType==2">通分</text><text v-if="awardType==1">神椰CoCo</text>奖励
			</view>
			<view class="zw_view" v-if="typeName == '官方直充'"></view>
			<view class="recharge" v-if="typeName == '官方直充'">
				<view class="recharge_l">充值账号</view>
				<input type="text" v-model="payData.account" placeholder="请填写要充值的账户"
					placeholder-class="placeholder_class">
			</view>
			<!-- <block>
				<view class="recharge" style="padding: 0rpx 40rpx 40rpx;">
					<view class="recharge_l">选择游戏</view>
					<view class="recharge_r">
						<text>英雄联盟</text>
						<image src="@/static/right_img.png" mode=""></image>
						<picker class="pick_box" @change="bindPickerChange" :value="index" :range="array">
							<view class="uni-input">{{array[index]}}</view>
						</picker>
					</view>
				</view>
				<view class="recharge" style="padding: 0rpx 40rpx 40rpx;">
					<view class="recharge_l">选择区服</view>
					<view class="recharge_r">
						<text>黑色玫瑰</text>
						<image src="@/static/right_img.png" mode=""></image>
					</view>
				</view>
			</block>
			<block>
				<view class="recharge" style="padding: 0rpx 40rpx 40rpx;">
					<view class="recharge_l">充值方式</view>
					<view class="recharge_r">
						<text>IOS端</text>
						<image src="@/static/right_img.png" mode=""></image>
					</view>
				</view>
			</block> -->
			<view class="zw_view"></view>
			<view class="introduce">
				<view class="introduce_title">商品详情</view>
				<view class="introduce_content">
					<rich-text :nodes="commodityDetails"></rich-text>
				</view>
			</view>
			<view class="zw_view"></view>
			<view class="introduce">
				<view class="introduce_title">使用规则</view>
				<view class="introduce_content">
					{{info.useDetail}}
				</view>
			</view>
		</view>
		<view class="zw"></view>
		<view class="operation">
			<view class="operation_button" @click="wxPay" v-if="!isSellOut">￥{{payNum}} 立即付款</view>
			<view class="operation_button sell_out" v-if="isSellOut">已售罄</view>
		</view>
	</view>
</template>

<script>
	import {
		thirdPlatformDetail,
		punchActivityBuy
	} from '@/api/sy.js'
	import wechat from '@/components/jweixin-module/wechat'
	export default {
		data() {
			return {
				typeIndex: 0,
				typeList: [{
					id: 1,
					value: '腾讯视频VIP'
				}, {
					id: 2,
					value: '腾讯视频7天会员'
				}, {
					id: 1,
					value: '腾讯视频VIP'
				}, ],
				faceValueIndex: 0,
				info: {}, //内容详情
				id: '', //活动id
				typeName: "官方直充",
				partyCommodityListDTO: [], //商品面值数组
				awardType: '', //积分类型 1：神椰CoCo  2：通分  3：不赠送积分
				awardAmount: '', //积分数量
				commodityDetails: '', //商品详情
				payNum: 0, //支付金额
				payData: {
					couponId: '', //优惠券id
					account: '', //充值帐号
					shopId:'',//
				},
				isSellOut: false, //是否售罄
				array: ['中国', '美国', '巴西', '日本'],
				index: 0,
			}
		},
		onLoad(option) {
			this.id = option.id
			this.payData.shopId = option.shopId
			this.getInfo()
		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			async getInfo() { //获取详情内容
				uni.showLoading({
					title: '加载中'
				})
				let data = {
					id: this.id, //活动id
				}
				try {
					var res = await thirdPlatformDetail(data)
					this.info = res.result
					this.partyCommodityListDTO = res.result.commodityListDTO[0].partyCommodityListDTO
					this.awardType = this.partyCommodityListDTO[0].awardType
					this.awardAmount = this.partyCommodityListDTO[0].awardAmount
					this.commodityDetails = this.partyCommodityListDTO[0].details
					this.payNum = this.partyCommodityListDTO[0].sellPrice
					this.payData.couponId = res.result.commodityListDTO[0].partyCommodityListDTO[0].couponId
					let info = res.result.commodityListDTO[0].partyCommodityListDTO[0].elementInfo
                    if(info){
                        info = JSON.parse(info)
                    }
					let gameTempaltePreviewList = res.result.commodityListDTO[0].partyCommodityListDTO[0].gameTempaltePreviewList
                    if(gameTempaltePreviewList){
                        gameTempaltePreviewList = JSON.parse(gameTempaltePreviewList)
                    }
					console.log('gameTempaltePreviewList',gameTempaltePreviewList)
					if (res.result.commodityListDTO[0].partyCommodityListDTO[0].salesStatus != 1) {
                        console.log('哈哈哈')
						this.isSellOut = true
					} else {
						this.isSellOut = false
					}
                    console.log('this.isSellOut',this.isSellOut)
					if (this.partyCommodityListDTO[0].productType == 1) {
						this.typeName = '官方直充'
					} else {
						this.typeName = '官方兑换码'
					}
                    
					uni.hideLoading()
				} catch {
					uni.hideLoading()
				} finally {
					setTimeout(res => {
						uni.hideLoading()
					}, 4000)
				}
			},
			changeType(item, index) { //类型选择
				this.typeIndex = index
				this.faceValueIndex = 0
				this.partyCommodityListDTO = item.partyCommodityListDTO
				this.awardType = this.partyCommodityListDTO[0].awardType
				this.awardAmount = this.partyCommodityListDTO[0].awardAmount
				this.commodityDetails = this.partyCommodityListDTO[0].details
				this.payNum = this.partyCommodityListDTO[0].sellPrice
				this.payData.couponId = this.partyCommodityListDTO[0].couponId
				if (this.partyCommodityListDTO[0].productType == 1) {
					this.typeName = '官方直充'
				} else {
					this.typeName = '官方兑换码'
				}
				if (this.partyCommodityListDTO[0].salesStatus != 1) {
					this.isSellOut = true
				} else {
					this.isSellOut = false
				}
			},
			changeFace(item, index) { //面值选择
				this.faceValueIndex = index
				if (item.productType == 1) {
					this.typeName = '官方直充'
				} else {
					this.typeName = '官方兑换码'
				}
				this.awardType = item.awardType
				this.awardAmount = item.awardAmount
				this.commodityDetails = item.details
				this.payNum = item.sellPrice
				this.payData.couponId = item.couponId
				if (item.salesStatus != 1) {
					this.isSellOut = true
				} else {
					this.isSellOut = false
				}
			},
			//微信支付
			async wxPay() {
				if (this.typeName == '官方直充' && this.payData.account == '') {
					uni.showToast({
						title: '请填写要充值的账户',
						icon: 'none'
					})
					return
				}
				if (this.isSellOut) {
					uni.showToast({
						title: '已售罄，无法购买',
						icon: 'none'
					})
					return
				}
				var _this = this
				uni.showLoading({
					title: '请求中',
					mask: true
				})
				this.disabled = true
				if (wechat.isWechat()) {
					let data = {
						...this.payData
					}
					var res = await punchActivityBuy(data)
					let orderId = res.result.orderId
					try {
						uni.hideLoading()
						// _this.payStatus = true
						wechat.wexinPay(res.result, function(callback) {
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/sy/mine-details/pay_success?orderId=' +
										orderId + '&type=' + '2'
								})
							}, 1000)
						}, async function(errorCallback) {
							_this.disabled = false
							uni.showToast({
								title: '取消支付成功',
								icon: 'none'
							})
						})
					} catch {
						_this.disabled = false
						uni.hideLoading()
					} finally {
						_this.disabled = false
						setTimeout(() => {
							uni.hideLoading()
						}, 2000)
					}
				} else {
					uni.hideLoading()
					uni.showToast({
						title: '请在微信客户端中使用',
						icon: 'none'
					})
				}
			},
		}
	}
</script>

<style>
	page {
		background-color: #F5F7F9;
	}

	view {
		box-sizing: border-box;
	}

	.head {
		background: linear-gradient(99.49deg, #12D4FF 0%, #8930FF 92.49%);
		width: 100%;
		height: 224rpx;
		position: relative;
	}

	.diamonds_img {
		width: 178rpx;
		height: 162rpx;
		position: absolute;
		right: 0;
		bottom: 14rpx;
	}

	.head_box {
		display: flex;
		width: 100%;
		height: 224rpx;
		position: absolute;
		top: 0;
		padding: 42rpx 50rpx;
	}

	.head_box_l {
		width: 108rpx;
		height: 108rpx;
		border-radius: 50%;
		border: 3rpx solid #FFFFFF;
	}

	.head_box_r {
		margin-left: 30rpx;
		flex: 1;
		margin-top: 6rpx;
	}

	.head_box_r_t {
		font-size: 34rpx;
		color: #FFFFFF;
		margin-bottom: 14rpx;
		width: 500rpx;
	}

	.head_box_r_b {
		font-size: 22rpx;
		color: #FFFFFF;
		padding: 0 16rpx;
		height: 36rpx;
		background: #2E6DEF;
		border-radius: 100rpx;
		text-align: center;
		line-height: 36rpx;
		width: fit-content
	}

	.main {
		background-color: #FFFFFF;
		border-radius: 40rpx 40rpx 0 0;
		margin: -40rpx 0 0 0;
		position: relative;
		z-index: 2;
		padding: 40rpx 0 40rpx;
	}

	.title {
		font-size: 34rpx;
		color: #222222;
		padding: 0 40rpx;
	}

	.type {
		display: flex;
		padding: 30rpx 0rpx 70rpx;
	}

	.type_box {
		height: 72rpx;
		border-radius: 100rpx;
		padding: 16rpx 28rpx;
		color: #555555;
		font-size: 28rpx;
		border: 2rpx solid #C0C0C0;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 40rpx 0rpx 0;
	}

	.type_box_change {
		border: 0;
		height: 72rpx;
		background: linear-gradient(90deg, #2720DE 0%, #6F00FC 98.24%);
		color: #FFFFFF;
	}

	.scroll_view {
		width: 100%;
		white-space: nowrap;
		padding: 0 40rpx;
		box-sizing: border-box;
	}

	/deep/ .scroll_view ::-webkit-scrollbar {
		display: none;
	}

	.face_value {
		display: flex;
		flex-wrap: wrap;
		border-bottom: 2rpx solid #D4D4D4;
		padding: 0 10rpx 40rpx;
		margin: 0 30rpx;
	}

	.face_value_box {
		height: 238rpx;
		border-radius: 20rpx;
		border: 2rpx solid #E7E7E7;
		min-width: 202rpx;
		margin-top: 30rpx;
		margin-left: 32rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.face_value_box:nth-child(3n+1) {
		margin-left: 0;
	}

	.face_value_box_change {
		background: url('/static/sy/mine-detailsmine-details//change_border.png') no-repeat;
		background-size: 100% 100%;
	}

	.check_true_img {
		position: absolute;
		width: 60rpx;
		height: 52rpx;
		right: 0;
		bottom: 0;
	}

	.face_value_sell_out {
		background: #B4B4B4;
		border-radius: 0rpx 20rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		text-align: center;
		width: 84rpx;
		height: 38rpx;
		line-height: 38rpx;
		position: absolute;
		top: 0;
		right: 0;
	}

	.face_value_box_name {
		font-size: 30rpx;
		color: #222222;
		margin-top: 40rpx;
		width: 180rpx;
		text-align: center;
	}

	.face_value_box_price {
		color: #FF3A3A;
		font-size: 32rpx;
		margin: 12rpx 0;
	}

	.old_price {
		font-size: 24rpx;
		color: #999999;
		text-decoration-line: line-through;
	}

	.expected_reward {
		height: 72rpx;
		border-radius: 8rpx;
		background-color: #FFEFEF;
		color: #FF1616;
		font-size: 30rpx;
		text-align: center;
		line-height: 72rpx;
		margin: 40rpx 30rpx;
	}

	.zw_view {
		width: 100%;
		height: 20rpx;
		background-color: #F5F7F9;
	}

	.recharge {
		background-color: #FFFFFF;
		padding: 40rpx;
		display: flex;
		align-items: center;
	}

	.recharge_l {
		font-size: 34rpx;
		color: #222222;
	}

	.recharge input {
		font-size: 34rpx;
		color: #222222;
		border: 2rpx solid #D3D3D3;
		background-color: #FCFCFC;
		border-radius: 8rpx;
		padding: 0 22rpx;
		flex: 1;
		margin-left: 14rpx;
		height: 80rpx;
	}

	.recharge_r {
		width: 520rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 34rpx;
		color: #757575;
		position: relative;
	}
	.pick_box{
		position: absolute;
		width: 100%;
		top: 0;
		opacity: 0;
	}

	.recharge_r image {
		width: 22rpx;
		height: 22rpx;
		margin-left: 20rpx;
	}

	.placeholder_class {
		color: #B1B1B1;
		font-size: 34rpx;
	}

	.introduce {
		background-color: #FFFFFF;
		padding: 40rpx;
	}

	.introduce_title {
		font-size: 34rpx;
		color: #222222;
		margin-bottom: 18rpx;
	}

	.introduce_content {
		font-size: 30rpx;
		color: #555555;
		line-height: 50rpx;
	}

	.operation {
		background-color: #FFFFFF;
		width: 100%;
		padding: 30rpx 30rpx 44rpx;
		position: fixed;
		bottom: 0;
		z-index: 2;
		border-top: 2rpx solid #E2E2E2;
	}

	.operation_button {
		width: 100%;
		height: 88rpx;
		border-radius: 12rpx;
		background: linear-gradient(90deg, #2720DE 0%, #6F00FC 98.24%);
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
	}

	.sell_out {
		background: #BABABA;
	}

	.operation_button:active {
		opacity: 0.8;
	}

	.zw {
		height: 220rpx;
		width: 100%;
	}
	.sell_out_active{
		color: #999999 !important;
	}
</style>
